package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import com.itheima.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;


@RestController
@Slf4j
@RequestMapping("upload")
public class UploadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    @PostMapping
    public Result upload(String username, Integer age, MultipartFile image) throws IOException {
        log.info("文件上传：{},{},{}",username,age,image);
       /* String originalFilename = image.getOriginalFilename();
        String suffix = image.getOriginalFilename().substring(originalFilename.lastIndexOf("."));
        String FinalFilename = UUID.randomUUID().toString() + suffix;
        image.transferTo(new File("D:/images" + FinalFilename));*/
        //调用aliossutils的方法
        String url = aliOSSUtils.upload(image);
        //把照片的url传给前端
        return Result.success(url);
    }


}
